import string
from changefile import HeadlineHandler
from xml.sax import parse

def menuitem(file):
    print 'got to menuitem'
    headlines = []
    parse('menu.xml', HeadlineHandler(headlines))
    h = HeadlineHandler(headlines)
    headlines = h.getheadlines()
    #count = h.getcount()
    s = []
    #START CREATION OF DOCUMENT
    s.append("""<?xml version="1.0" encoding="utf-8"?>
    <siteData>
        <menu>\n""")
    i = 0
    for n in headlines:
        s.append("        <item>"+headlines[i]+"</item>\n")
        i = i + 1
    else:
        s.append("        <item>"+file+"</item>\n")
        s.append("""    </menu>
    </siteData>""")
    
    # write the result
    print 'begin writing to menu'
    f = open('menu.xml', 'w')
    i = 0
    for n in s:
        f.write(s[i])
        i = i + 1
    else:
        f.close()
    print 'closed file'